import 'package:exams_app/gen_a/A.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import '../exams_module/exams_complete_page.dart';
import 'myexams_logic.dart';
import 'package:get/get.dart';
import 'myexams_detail_page.dart';
class MyExamsPages extends StatelessWidget {

  MyExamsLogic logic = Get.put(MyExamsLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('我的考试'),
          centerTitle: true,
        ),
        body: GetBuilder<MyExamsLogic>(


          initState: (sz){
           logic.requestData(true,page: 0);

          },
          builder: (logic) {
            return Container(
              color: HexColor('#F7F7F7'),
              child: EasyRefresh.custom(
                emptyWidget: logic.emptyData(),
                controller: logic.esController,
                onLoad: logic.onLoad,
                onRefresh: logic.onRefresh,
                header: MaterialHeader(),
                footer: MaterialFooter(),
                slivers: [
                  SliverList(
                      delegate: SliverChildBuilderDelegate(_buildListItem,
                          childCount: logic.dataList.length)),
                ],
              ),
            );

          },
        ));
  }

  Widget _buildListItem(BuildContext context, int index) {
    Data model = logic.dataList[index];

    return GestureDetector(
      onTap: () {
        // Get.to(MyExamsDetailPage(model.id));

        // Get.to(ExamsCompletePage(
        //   model.id,
        //   title: '考试详情',
        // ));
      },
      child: Container(
        height: 120,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(5.0),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(

              width: Get.width,
              margin: EdgeInsets.only(left: 15, top: 15),
              child: Row(
                children: [
                  Image.asset(A.assets_ks),
                  SizedBox(
                    width: 5,
                  ),
              Container(
                width: Get.width-80,
                // color: Colors.yellow,
                child:  Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('${model.textName}'),
                    Text('${model.state}')
                  ],
                ),
              )
                ],
              ),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Visibility(child: Container(
                  margin: EdgeInsets.only(left: 15, top: 15),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '${model.scores}',
                        style: TextStyle(
                            fontSize: 18,
                            fontWeight: FontWeight.w500,
                            color: HexColor('#333333')),
                      ),
                      Text(
                        '得分',
                        style:
                        TextStyle(fontSize: 14, color: HexColor('#999999')),
                      )
                    ],
                  ),
                ),visible: model.state=='新建'?false:true,),
                Container(
                  margin: EdgeInsets.only(top: 15, left: 15),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        '${model.dateStart}',
                        style: TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                            color: HexColor('#333333')),
                      ),
                      Text(
                        '考试时间',
                        style:
                            TextStyle(fontSize: 14, color: HexColor('#999999')),
                      ),
                    ],
                  ),
                )
              ],
            )
          ],
        ),
        margin: EdgeInsets.only(top: 10),
      ),
    );
  }
}
